
$("button").click(() => {
    const val = $("textarea").val();
    if(localStorage.log){
        let log = JSON.parse(localStorage.getItem('log'));
        log.push(val);
        localStorage.log = JSON.stringify(log);
    }else{
        let arr = [];
        arr.push(val);
        localStorage.log = JSON.stringify(arr);
    }
    $("textarea").val("");
    getList();
})

const getList = () => {
    let log = JSON.parse(localStorage.getItem('log')); 
    if(!log) return;
    let str = "<ul>";
    for(let i of log){
        str +=  `<li>${i}</li>`
    }
    str += "</ul>";
    $("#list").html(str);
}
getList();

const isOnLine = () => {
    if(navigator.onLine){
        alert("onLine")
    }else{
        alert("offLine")
    }
}
isOnLine();

window.addEventListener("offline", function(e) {alert("掉线");})

window.addEventListener("online", function(e) {alert("上线");})